package cn.dankal.flyaudio.adapter;

import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.shehuan.niv.NiceImageView;

import cn.dankal.basiclib.base.recyclerview.BaseRecyclerViewAdapter;
import cn.dankal.basiclib.base.recyclerview.BaseRecyclerViewHolder;
import cn.dankal.basiclib.util.image.PicUtils;
import cn.dankal.flyaudio.R;
import cn.jpush.im.android.api.model.UserInfo;

public class GroupMembersAdapter extends BaseRecyclerViewAdapter<UserInfo> {
    @Override
    protected int getLayoutResId(int viewType) {
        return R.layout.item_group_members;
    }

    @Override
    protected BaseRecyclerViewHolder getViewHolder(ViewGroup parent, View rootView, int viewType) {
        return new ViewHolder(rootView);
    }

    public class ViewHolder extends BaseRecyclerViewHolder<UserInfo> {

        public ViewHolder(View itemView) {
            super(itemView);
        }

        @Override
        public void onBindData(UserInfo data, int position) {
            if ("-----1".equals(data.getNickname())) {
                setVisibility(R.id.fl_del, true);
                setVisibility(R.id.fl_add, false);
                setVisibility(R.id.iv_avatar, false);
                setText(R.id.tv_nickname, "");
            } else {
                setText(R.id.tv_nickname, data.getNickname());
                if (TextUtils.isEmpty(data.getUserName())) {
                    setVisibility(R.id.fl_del, false);
                    setVisibility(R.id.fl_add, true);
                    setVisibility(R.id.iv_avatar, false);
                } else {
                    ImageView imageView = itemView.findViewById(R.id.iv_avatar);
                    setVisibility(R.id.fl_del, false);
                    setVisibility(R.id.fl_add, false);
                    setVisibility(R.id.iv_avatar, true);
                    PicUtils.loadAvatar(data.getAvatarFile(), imageView);
                }
            }

        }
    }
}
